package windows.propertyWindow
{
	import windows.*;
	import com.bit101.components.Window;
	import baseitems.Base;
	import property.ItemType;

	import windows.propertyWindow.PropertyLayerView;
	import windows.propertyWindow.PropertyNodeView;
	import windows.propertyWindow.PropertyLabelView;
	import windows.propertyWindow.PropertyFormView;
	
	/**
	 * Окно с пропертями
	 * @author yaempechenki@gmail.com
	 */
	public class PropertiesWindow extends Window
	{
		private var nodePropertyView:PropertyNodeView;
		private var layerPropertyView:PropertyLayerView;
		private var labelPropertyView:PropertyLabelView;
		private var formPropertyView:PropertyFormView;
	
		public function PropertiesWindow()
		{
			title = "Properties";
			hasMinimizeButton = true;
			width = 120;
			height = 280;
			
			nodePropertyView = new PropertyNodeView();
			nodePropertyView.visible = false;
			addChild(nodePropertyView);
			
			layerPropertyView = new PropertyLayerView();
			layerPropertyView.visible = false;
			addChild(layerPropertyView);
			
			labelPropertyView = new PropertyLabelView();
			labelPropertyView.visible = false;
			addChild(labelPropertyView);
			
			formPropertyView = new PropertyFormView();
			formPropertyView.visible = false;
			formPropertyView.addEventListener(GuiEvent.ADD_SKETCH, onAddSketch);
			formPropertyView.addEventListener(GuiEvent.FORM_SIZE_CHANGED, onFormSizeChanged);
			addChild(formPropertyView);
			
			refresh();
		}
		
		public function refresh():void {
			var type:String = Controller.instance.haveSelected? Controller.instance.selectedObject.type : "";
			// с установкой визибла сразу вызывается рефреш
			formPropertyView.visible = (type=="");
			nodePropertyView.visible = (type!="");
			layerPropertyView.visible = (type == ItemType.LAYER);
			labelPropertyView.visible = (type == ItemType.LABEL);
		}
		
		private function onAddSketch(event:GuiEvent):void {
           dispatchEvent(new GuiEvent(GuiEvent.ADD_SKETCH));
        }
		
		private function onFormSizeChanged(event:GuiEvent):void {
			dispatchEvent(new GuiEvent(GuiEvent.FORM_SIZE_CHANGED, event.data));
        }

	}
}